// uniCloud/cloudfunctions/deleteUser/index.js
'use strict';
exports.main = async (event, context) => {
  const db = uniCloud.database()
  const { userId } = event

  try {
    // 执行删除操作
    const result = await db.collection('user')
      .doc(userId)
      .remove()

    if (result.deleted === 1) {
      return {
        code: 0,
        message: '用户删除成功'
      }
    } else {
      return {
        code: 404,
        message: '用户不存在'
      }
    }
  } catch (error) {
    console.error('删除用户失败:', error)
    return {
      code: 500,
      message: '删除用户失败',
      error: error.message
    }
  }
}